<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>博客详情</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <!--    引入typo.css插件-->
    <link rel="stylesheet" href="../static/css/typo.css" th:href="@{/css/typo.css}">
    <!--引入动画的插件-->
    <!--    引入生成目录的插件-->
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css" th:href="@{/lib/tocbot/tocbot.css}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css"/>


    <!--    引入代码高亮的插件-->
    <link rel="stylesheet" href="../static/lib/prism/prism.css" th:href="@{/lib/prism/prism.css}">

    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>

<!--导航的部分--><!--有线程的组件-->
<nav class="ui inverted vertical attach segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <!--左边的导航-->
        <div class="ui secondary inverted stackable menu">
            <h2 class="ui header teal item">Timous</h2>
            <a href="#" th:href="@{/}" class="m-item item m-mobile-hide"><i class="mini home icon"></i>首页</a>
            <a href="#" th:href="@{/types/-1}" class="m-item item m-mobile-hide"><i class="mini idea icon"></i>分类</a>
            <a href="#" th:href="@{/tags/-1}" class="m-item item m-mobile-hide"><i class="mini tags icon"></i>标签</a>
            <a href="#" th:href="@{/archives}" class="m-item item m-mobile-hide"><i class="mini clone icon"></i>归档</a>
            <a href="#" th:href="@{/blogabout}"   class="m-item item m-mobile-hide"><i class="mini info icon"></i>关于我</a>
            <a href="#" th:href="@{/types/-1}"   class="m-item item m-mobile-hide"><i class="mini music icon"></i>音乐盒</a>
            <a href="#" th:href="@{/types/-1}"  class="m-item item m-mobile-hide"><i class="mini user icon"></i>友人帐</a>
            <a href="#" th:classappend="${num==8} ? 'active'" class="m-item item m-mobile-hide"><i class="mini photo icon"></i>照片墙</a>
            <div class="m-item right item m-mobile-hide">
                <div class="ui icon inverted transparent input">
                    <input type="text" placeholder="Search...">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>


        <!--        加一个隐藏的图标-->
        <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </div>


</nav>


<!--中间的内容-->
<div id="waypoint" class="m-padded-tb-massive m-container-small">
    <div class="ui container">


        <!--        头部的信息-->
        <div class="ui top attached segment">
            <div class="ui link list horizontal">
                <div class="item">
                    <img src="https://picsum.photos/id/1005/100/100" th:src="@{${blog.user.avatar}}" alt=""
                         class="ui avatar image">
                    <div class="content">

                        <a href="#" th:text="${blog.user.nickname}" class="header">陈留红</a>

                    </div>
                </div>

                <div class="item">

                    <i class="icon calendar"></i><span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2017-10-1</span>

                </div>

                <div class="item">

                    <i class="icon eye"></i><span th:text="${blog.views}">12</span>

                </div>

            </div>
        </div>


        <!--        图片的区域部分-->
        <div class="ui attached segment">
            <img src="https://picsum.photos/id/1005/800/400" th:src="${blog.firstPicture}" alt=""
                 class="ui rounded fluid image">
        </div>


        <!--        博客的内容的部分-->
        <div class="ui attached m-padded-tb-huge segment animate fadeIn ">
            <div class="ui right aligned basic segment">
                <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
            </div>

            <h2 class="ui center aligned header" th:text="${blog.title}">关于可以联系的清单</h2>
            </br>





            <!--中间的主要的内容，主要放置的是html， 现在获取到的是markdown的格式，需要和转化为markdown再显示-->
            <!--text 是已转移的-->
            <div id="content" th:utext="${blog.content}" class="typo  typo-selection js-toc-content m-padded-left m-padded-tb-response ">


                <!--内容部分的获取，格式的更改  需要给我们渲染一下-->




            </div>


            <!--            标签-->
            <div class="m-padded-left">
                <a href="#" th:each="tag : ${blog.tags}" th:text="${tag.name}"
                   class="ui basic teal left pointing label">方法论</a>
            </div>


            <div th:if="${blog.apprication}">

                <!--            赞赏-->
                <div class="ui center aligned basic segment">
                    <button id="payButton" class="ui timous orange circular basic button">赞赏</button>
                </div>

                <!--            二维码-->

                <div class="ui flowing popup custom transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <div class="image">
                                <img src="../static/images/wechat.png" th:src="@{/images/wechat.png}" alt=""
                                     style="width: 120px" class="ui rounded bordered image">
                                <div>支付宝支付</div>
                            </div>

                            <div class="image">
                                <img src="../static/images/wechat.png" th:src="@{/images/wechat.png}" alt=""
                                     style="width: 120px" class="ui rounded bordered image">
                                <div>微信支付</div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>


        </div>


        <!--        博客下面的信息-->
        <div class="ui attached  positive message" th:if="${blog.shareStatus}">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span th:text="${blog.user.nickname}">陈留红</span> <a href="" th:href="@{/blogabout}"
                                                                                   target="_blank">（联系作者）</a></li>
                        <li>发表时间： <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}" > 2020-5-19</span>
                        </li>
                        <li>版权声明： 自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                        <li>公众号转载： 请在文末添加作者公众号二维码</li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img src="../static/images/wechat.png" th:src="@{/images/wechat.png}" alt=""
                         class="ui right floated rounded bordered image" style="width: 110px;">
                </div>
            </div>
        </div>


        <!--        博客的留言的区域-->
        <div class="ui bottom attached segment" th:if="${blog.commentAbled}">
            <div  id="comment-container" class="ui teal segment">

                <div th:fragment="commentList">

                    <div class="ui comments" style="max-width: 100%">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://picsum.photos/id/1005/800/400" th:src="${comment.avatar}">
                            </a>
                            <div class="content">
                                <span class="author" th:text="${comment.nickname}">
                                    Matt
                                </span>

                                <div class="ui mini basic teal left pointing m-padded-mini label" th:if="${comment.adminComment}">博主</div>
                                <div class="metadata">
                                    <span class="date" th:text="${#dates.format(comment.createTime , 'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply" th:attr="data-commentid=${comment.id} , data-commentnickname=${comment.nickname}" data-commentid="1" data-commentnickname="Matte" onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="https://picsum.photos/id/1005/800/400" th:src="${reply.avatar}">
                                    </a>
                                    <div class="content">
                                        <a class="author" >
                                            <span th:text="${reply.nickname}"></span>
                                            <div class="ui mini basic teal left pointing m-padded-mini label" th:if="${reply.adminComment}">博主</div>
                                            &nbsp;<span class="m-teal">@</span>
                                            <span th:text="${reply.parentComment.nickname}" class="m-teal">@小白</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date" th:text="${#dates.format(reply.createTime , 'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">
                                            How artistic!
                                        </div>
                                        <div class="actions">
                                            <a class="reply" th:attr="data-commentid=${reply.id} , data-commentnickname=${reply.nickname}" data-commentid="1" data-commentnickname="Matte" onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--                提交留言的区域-->
            <div id="comment-form" class="ui form">

                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">

                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息"></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">

                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" placeholder="昵称"  th:value="${session.user}!=null ? ${session.user.nickname}" name="nickname">
                        </div>

                    </div>

                    <div class="field m-mobile-wide m-margin-bottom-small">

                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}" name="email">
                        </div>

                    </div>

                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <button id="commentpost-btn" type="button" class="ui teal m-mobile-wide button">
                            <i class="edit vertical icon"></i>发布
                        </button>
                    </div>

                </div>

            </div>





            <div class="ui form">

            </div>
        </div>


    </div>
</div>


<div id="toolBar" class="m-padded m-fixed m-right-bottom" style="display: none;">
    <div class="ui vertical icon buttons ">
        <button type="button" class="ui teal button toc">目录</button>
        <a href="#comment-container" type="button" class="ui teal button">留言</a>
        <button class="ui wechat  icon button"><i class="weixin icon"></i></button>
        <div id="toTop-Button" class="ui icon button"><i class="chevron up icon"></i></div>
    </div>
</div>


<!--            二维码-->

<div id="qrcode" class="ui flowing popup wechat-qr transition hidden" style="width: 130px;">
    <!--    <img src="./static/images/wechat.png" alt="" class="ui rounded image" style="width:120px;">-->
</div>


<div class="ui toc-container flowing popup  transition hidden" style="width: 250px;">
    <ol class="js-toc"></ol>
</div>


<!--底部的内容-->
<footer  class="ui segment inverted vertical me-padded-td-mini">
    <div class=" m-padded-tb-massive ui center aligned container">
        <!--grid会把整个页面分成16分-->
        <div class="ui divided  inverted stackable grid ">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.png" th:src="@{/images/wechat.png}" class="ui rounded image"
                             alt="" style="width:110px;">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.png" th:src="@{/images/wechat.png}" class="ui rounded image"
                             alt="" style="width:110px;">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-space m-opacity-mini">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin m-text-space m-opacity-mini" th:text="#{index.email}">Email：1844736251@qq.com</a>
                    <a href="#" class="item m-text-thin m-text-space m-opacity-mini" th:text="#{index.QQ}">QQ:1844736251</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-space m-opacity-mini">本网站营业时间</h4>
                <div id="time"></div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-space m-opacity-mini">Copyright © 2020-2021 Timous Designed By 陈留红</p>
    </div>
</footer>


<!-- 引入Jquery-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<!-- 引入组件库 -->
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>

<!--平滑滚动-->
<script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>

<!--代码高亮的插件-->
<script src="../static/lib/prism/prism.js" th:src="@{/lib/prism/prism.js}"></script>

<!--引入生成目录的js文件-->
<script src="../static/lib/tocbot/tocbot.min.js" th:src="@{/lib/tocbot/tocbot.min.js}"></script>
<!--生成二维码的插件的js引入-->
<script src="../static/lib/qrcode/qrcode.min.js" th:src="@{/lib/qrcode/qrcode.min.js}"></script>
<!--滚动侦测的插件-->
<script src="../static/lib/waypoints/jquery.waypoints.min.js"
        th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>


<script th:inline="javascript" src="../static/js/details.js" th:src="@{/js/details.js}"></script>

<script src="../static/js/me.js" th:src="@{/js/me.js}"></script>
<!--数据的校验-->
<script th:inline="javascript">

    /*评论的表单验证*/
    $('.ui.form').form({
        fields:{
            title:{
                identifier: 'content',
                rules:[{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            },
            content:{

                identifier: 'nickname',
                rules:[{
                    type: 'empty',
                    prompt: '请输入你的昵称'
                }]
            },
            type:{
                identifier: 'email',
                rules:[{
                    type: 'empty',
                    prompt: '请输入正确的邮箱地址'
                }]
            }
        },
    });


    //页面加载完成之后需要做加载博客的评论
    $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/17");


    $("#commentpost-btn").click(function () {
        var boo = $('.ui.form').form('validate form');

        if(boo){
            console.log('校验成功');
            postData();
        }else{
            console.log('校验失败');
        }

    });

    function postData(){
        $("#comment-container").load(/*[[@{/comments}]]*/"",{
            "parentComment.id":$("[name='parentComment.id']").val(),
            "blog.id":$("[name='blog.id']").val(),
            "nickname":$("[name='nickname']").val(),
            "email":$("[name='email']").val(),
            "content":$("[name='content']").val()
        },function (responseTxt,statusTxt,xhr) {
            clearContent();
            //滚动到最上面的评论
            //   $(window).scrollTo($('#comment-container') , 500);
            //处理业务逻辑等  清除工作

        })
    }
    function clearContent() {

        $("[name='content']").val(''),
        $("[name='parentComment.id']").val(-1)
        $("[name='content']").attr("placeholder" , "请输入评论信息...");


    }

    function reply(obj) {

        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');

        console.log(obj);

        $("[name='content']").attr("placeholder" , "@"+commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);

        $(window).scrollTo($('#comment-form') , 500);
    }


</script>

<script>


    // 运行时间统计
    function secondToDate(second) {
        if (!second) {
            return 0;
        }
        var time = new Array(0, 0, 0, 0, 0);
        if (second >= 365 * 24 * 3600) {
            time[0] = parseInt(second / (365 * 24 * 3600));
            second %= 365 * 24 * 3600;
        }
        if (second >= 24 * 3600) {
            time[1] = parseInt(second / (24 * 3600));
            second %= 24 * 3600;
        }
        if (second >= 3600) {
            time[2] = parseInt(second / 3600);
            second %= 3600;
        }
        if (second >= 60) {
            time[3] = parseInt(second / 60);
            second %= 60;
        }
        if (second > 0) {
            time[4] = second;
        }
        return time;
    }

    function setTime() {
        /*此处为网站的创建时间*/
        var create_time = Math.round(new Date(Date.UTC(2020, 1, 25, 15, 15, 15)).getTime() / 1000);
        var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
        currentTime = secondToDate((timestamp - create_time));
        currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
            + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
            + '秒';
        document.getElementById("time").innerHTML = currentTimeHtml;
    }

    setInterval(setTime, 1000);


    $("#newblog-container").load(/*[[@{/footer/newblog}]]*/"/footer/newblog");

</script>
</body>
</html>